<?php

class TaskComments extends Model {

	function TaskComments() {
		parent::Model();
	}

	function create( $task_id, $account_id, $text, $add_date = false ) {
		if($add_date) {
			$sql = 'insert into `task_comments`'.
				'(`task_id`, `account_id`, `text`, `add_date`)'.
				'values(?, ?, ?, ?)';
			$this->db->query( $sql, array( $task_id, $account_id, $text, $add_date) );
		} else {
			$sql = 'insert into `task_comments`'.
				'(`task_id`, `account_id`, `text`, `add_date`)'.
				'values(?, ?, ?, now())';
			$this->db->query( $sql, array( $task_id, $account_id, $text) );
		}
	}

	function fetch( $comment_id ) {
		$sql = 'select * from `task_comments` where `comment_id`=?';
		$result = $this->db->query( $sql, array( $comment_id ) );
		return $result->row();
	}
	
	function fetch_by_task( $task_id ) {
		$sql = 'select * from `task_comments` where `task_id`=?';
		$result = $this->db->query( $sql, array( $task_id ) );
		return $result->result();
	}

	function remove( $comment_id ) {
		$sql = 'delete from `task_comments` where `task_id`=?';
		$this->db->query( $sql, array( $comment_id ) );
	}
}


?>
